
 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gene.core;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author callagun
 */
public class GraphicDevice {

    Graphics g = Core.getInstance().getCoreGraphics();

    int [] memory;

    
    public GraphicDevice(int w,int h){
        memory = new int[w * h];
    }


public void clearMemory(){


}

public void flush(){

 //Graphics Core.getInstance() = coreInstance.getCoreGraphics();

    int j = memory.length;
    Image tmp = Image.createRGBImage(memory,Core.getInstance().W , Core.getInstance().H, true);
	
    Core.graphics.drawImage(tmp,0,0,0);
}

public void bufferImage(Image img,int x, int y, int anchor){

}

/////////////////////////// sessao graficos /////////////////////////////
    //bufferiza no segundo passo;
    public void buffer(Component compo) {
        compo.draw();
    }

    public void draw_Pixel(int col, int row, int color) {
        g.setColor(color);
        g.drawLine(col, row, col+1, row+1);
    }
 int i=0;

 public void clearScreen() {
       
        //i+=0x00040000;
        g.setColor(0x00000000);
        //graphics.setColor(i);
        g.fillRect(0, 0, Core.W, Core.H);
    }

    /**
     * Save images on buffer to show him on <code>paint()</code>
     * @param x postition X on device screen
     * @param y postition Y on device screen
     */
    public void buffer(Image img, int x, int y) {

        if (img != null && (Core.GLOBAL_TICKS % Core.FRAME_SKIP) == 0) {
            //se estiver setado para rotacionar , recria todas as imagens re-orientando-as
        /*    if (orientation > 0) {
                graphics.drawImage(Image.createImage(img, 0, 0, img.getWidth(), img.getHeight(), orientation), y, x, 0);
            } else {*/
                //g.drawImage(img, x, y, 0);
            //}
        }
        img = null;
    }

    /**
     * clear the device screen and show all elements of current <code>Screen</code>
     */
    public void /*flush*/ paint() {
      if(Core.GLOBAL_TICKS % Core.FRAME_SKIP == 0){

        //int time = (int) (System.currentTimeMillis() - Core.getInstance().start)>>3;
                Core.getInstance().flush();

                clearScreen();
                //Core.getInstance().fpsCont++;

        }


        if ((Core.GLOBAL_TICKS % 20) == 0) {
            System.gc();
        }

        Core.getInstance().sync();//list = null;
    }

    /*
    public void bufferImage(int bitmap[]){
 int i = bitmap.length;
        for(int j=0;j<i;j++){
            memory[j]=bitmap[j];
        }
    
    }
     */


    /**
     * Get the rbg background color array;
     * @return
     */
    public int getRGB_Background() {
        return Core.color_background;
    }

    /*
   private void transformMemoryToImage(){
    Core._image = Image.createRGBImage(memory,Core.W,Core.H, true);
    
   }*/

}